export default {
    props: {
        // exportTitle: {
        //     type: String,
        //     default: `导出周报-${new Date().format('yyyy-MM-dd hh-mm-ss')}-${new Date().getTime()}`
        // } //导出文件标题
    },
    data() {
        return {
            exportTable: {
                isNormal: false,
                loading: false,
                rows1: [],
                rows2: [],

                restableData1: [],
                restableData2: [],
            }
        }
    },
    methods: {
        exportExcel() {
            this.exportTable.isNormal = false;
            this.exportTitle = this.exportTitle || `导出周报-${new Date().format('yyyy-MM-dd hh-mm-ss')}-${new Date().getTime()}`
            this.exportTable.loading = true
            // let parmars = {
            //     uid: this.uid, //测试时随意整数
            //     pageNo: this.pagination.pageNo,
            //     pageSize: this.pagination.pageSize
            // };
            this.workAPI().then(res => {
                this.exportTable.loading = false
                let building = {
                    ...res.building
                };
                let builded = {
                    ...res.builded
                };
                building.weeklist.map((item, index) => {
                    this.restableData1.push({
                        xh: index + 1,
                        ...item,
                    });
                });
                let Html = `在建项目（共${building.projectTotal}个`;
                let len = building.list.length;
                this.buildingLen = building.weeklist.length;
                if (len < 1) {
                    Html += ")";
                } else {
                    Html += "，";
                    building.list.map((item, index) => {
                        Html += `${index === 0 ? "其中" : ""}${item.name + item.num}个${
                            len != index + 1 ? "，" : "）"
                            }`;
                    });
                }
                this.exportTable.Html = Html;
                this.exportTable.rows1 = (this.restableData1 || []).map(r => this.columns.map(col => r[col.prop]))
                builded.weeklist.map((item, index) => {
                    this.restableData2.push({
                        xh: index,
                        ...item,
                    });
                });
                let Html2 = `重点运维项目（共${builded.projectTotal}个`;
                let len2 = builded.list.length;
                if (len2 < 1) {
                    Html2 += ")";
                } else {
                    Html2 += "，";
                    builded.list.map((item, index) => {
                        Html2 += `${index === 0 ? "其中" : ""}${item.name + item.num}个${
                            len2 != index + 1 ? "，" : "）"
                            }`;
                    });
                }
                this.exportTable.Html2 = Html2;
                this.exportTable.rows2 = (this.restableData2 || []).map(r => this.columns.map(col => r[col.prop]))
                this.$nextTick(() => {
                    this.$refs.exportTable.export(this.exportTitle)
                })
                // return
                // this.exportTable.loading = false
                // this.$hideLoading()
                // let tableData = res.building.weeklist;
                // tableData = [...tableData, ...res.builded.weeklist];
                // this.exportTable.rows = (tableData || []).map(r => this.columns.map(col => r[col.prop]))
                // this.$nextTick(() => {
                //     this.$refs.exportTable.export(this.exportTitle)
                // })
            })
        },
        exportExcelMonth() {
            this.exportTable.isNormal = true;
            this.exportTitle = this.exportTitle || `导出月度考评-${new Date().format('yyyy-MM-dd hh-mm-ss')}-${new Date().getTime()}`
            this.exportTable.loading = true
            this.workAPI().then(res => {
                this.exportTable.loading = false
                let tableData = res.building.weeklist;
                tableData = [...tableData, ...res.builded.weeklist];
                this.exportTable.rows1 = (tableData || []).map(r => this.columns.map(col => r[col.prop]))
                this.$nextTick(() => {
                    this.$refs.exportTableMonth.exportMonth(this.exportTitle)
                })
            })
        }
    }
}